package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.entity.Test_plan;
import com.aaa.service.Test_plan_sdsService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("test_plan_sds")
public class Test_plan_sdsController extends BaseController{

    @Autowired
    private Test_plan_sdsService plan_sdsService;

    MyReturn myReturn=new MyReturn();

    @RequestMapping("toShowSdsPlan.do")
    public String toShowUserPage(){
        return "showSdsPlan";
    }

    /**
    * @Author: WTH
    * @Description: 查询,分页,计算总条数
    * @Date:2022-07-03 18:06
    * @Params:
    */
    @ResponseBody
    @RequestMapping("selectPlanSds.do")
    public MyReturn selectPlanSds(Test_plan plan_sds){
        Page<Test_plan> test_plans = plan_sdsService.selectSdsPlan(plan_sds);
        myReturn.setData(test_plans.getResult());
        super.getSuccessResult(myReturn);
        myReturn.setCount(test_plans.getTotal());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 删除，批量删除
    * @Date:2022-07-03 18:08
    * @Params:
    */
    @ResponseBody
    @RequestMapping("deletePlanSds.do")
    public MyReturn deletePlanSds(String id){
        boolean b = plan_sdsService.deleteSdsPlan(id);
        if(b){
            return super.getSuccessResult(myReturn);
        }else{
            return super.getFailResult(myReturn);
        }
    }


    /**
    * @Author: WTH
    * @Description: 新增
    * @Date:2022-07-03 18:09
    * @Params:
    */
    @ResponseBody
    @RequestMapping("addPlanSds.do")
    public MyReturn addPlanSds(Test_plan plan_sds){
        plan_sds.setCreate_time(new Date());
        Enum01 enum01 = plan_sdsService.addSdsPlan(plan_sds);
        myReturn.setCode(enum01.getCode());
        myReturn.setMsg(enum01.getMsg());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-07-03 18:11
    * @Params:
    */
    @ResponseBody
    @RequestMapping("updatePlanSds.do")
    public MyReturn updatePlanSds(Test_plan plan_sds){
        plan_sds.setUpdate_time(new Date());
        Enum01 enum01 = plan_sdsService.updateSdsPlan(plan_sds);
        myReturn.setCode(enum01.getCode());
        myReturn.setMsg(enum01.getMsg());
        return myReturn;
    }
}
